<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minMoves = function (nums, limit) {
      let tempArr = new Array(2 * limit + 2).fill(0), n = nums.length, result = 0
      for (let i = 0; i < n / 2; i++) {
        let [pre, next] = [nums[i], nums[n - 1 - i]]
        let [minNum, maxNum] = [Math.min(pre, next), Math.max(pre, next)]
        tempArr[2] += 2
        tempArr[pre + next] -= 1
        tempArr[pre + next + 1] += 1
        tempArr[1 + minNum] -= 1
        tempArr[limit + maxNum + 1] += 1
      }
      result = tempArr[2]
      for (let i = 2; i < tempArr.length; i++) {
        tempArr[i] += tempArr[i - 1]
        result = Math.min(result, tempArr[i])
      }
      return result
    };
    console.log(minMoves([1, 2, 4, 3], 4));
  </script>
</body>

</html>